﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCTask.Models;
using System.Web.Script.Serialization;

namespace MVCTask.Controllers
{
    public class HomeController : Controller
    {
        private TaskContext db = new TaskContext();
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to MVCTaskManager";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult ImportExport()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Import(string text)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            var c = js.Deserialize<List<Task>>(text);
            foreach (var item in c)
            {
                db.Tasks.Add(item);
                db.SaveChanges();
            }
            return View(c);
        }
    }
}
